<template>
  <div class="app-main">
    <div class="divHead">
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content bg-purple">仓库编号</div>
          <div class="el-input el-input--medium">
            <el-input
              v-model="form.num"
              placeholder="请输入内容"
              autocomplete="off"
            ></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">仓库名称</div>
          <div class="el-input el-input--medium">
            <el-input
              v-model="form.name"
              placeholder="请输入内容"
              autocomplete="off"
            ></el-input>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">仓库状态</div>
          <div></div>
          <el-select
            v-model="form.state"
            placeholder="请选择"
            class="el-input el-input--medium el-input--suffix"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <div class="divButton">
          <button class="minorImportantButton btnSearch" @click="query">
            搜索
          </button>
          <button class="unimportanceButton" @click="reset">重置</button>
        </div>
      </el-row>
    </div>
    <div class="divContent">
      <button class="importantButton btnAdd" @click="addFn">
        新增仓库
      </button>
       <div v-if="isshow" class="emptyTip">
       <div class="img">
       </div>
         <p>暂无库区</p>
     </div>
     <div v-else>
       <el-table :data="tableData?.records" stripe style="width: 100%">
        <el-table-column type="index" label="序号" width="100">
        </el-table-column>
        <el-table-column prop="code" label="仓库编码" width="100">
        </el-table-column>
        <el-table-column prop="name" label="仓库名称"> </el-table-column>
        <el-table-column prop="type" label="仓库类型">
          <template slot-scope="scope">
            <span>{{
              scope.row.type === "ZZ"
                ? "中转仓"
                : scope.row.type === "JG"
                ? "加工仓"
                : scope.row.type === "CB"
                ? "储备仓"
                : "冷藏仓"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="location" label="省市区"> </el-table-column>
        <el-table-column prop="address" label="详细地址"> </el-table-column>
        <el-table-column prop="status" label="仓库状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status === 0 ? "停用" : "启用" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="surface" label="仓库面积"> </el-table-column>
        <el-table-column prop="includedNum" label="库区数量"> </el-table-column>
        <el-table-column prop="personName" label="负责人"> </el-table-column>
        <el-table-column prop="phone" label="联系电话"> </el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="180px">
        </el-table-column>
        <el-table-column prop="address" label="操作" width="180px">
          <template slot-scope="scope">
            <span style="color: #ffb200" @click="update(scope.row)">编辑</span>&nbsp;&nbsp;
            <span style="color: #ffb200" @click="putwarehouse(scope.row)"
              >{{scope.row.status===1?'停用':'启用'}}</span
            >&nbsp;&nbsp;
            <span style="color: #ffb200" @click="del(scope.row.id)">删除</span>
          </template>
        </el-table-column>
      </el-table>
     </div>
    </div>
    <PageTool
     :total="tableData.total"
      :paginationPage="frompage.current"
      :paginationPagesize="frompage.size"
      @pageChange="pageChangeFn"
      @pageSizeChange="pageSizeChangeFn"/>
  </div>
</template>

<script>
import PageTool from '@/compont/PageTool.vue'
import { warehouse, delwarehouse, putwarehouse } from '@/api/warehouse'
export default {
  components: {
    PageTool
  },
  data () {
    return {
      form: {
        num: '',
        name: '',
        state: ''
      },
      isshow: false,
      frompage: {
        like_code: '',
        like_name: '',
        current: 1,
        size: '',
        descs: 'createTime'
      },
      tableData: {},

      options: [
        {
          value: null,
          label: '全部'
        },
        {
          value: '1',
          label: '启用'
        },
        {
          value: '0',
          label: '禁用'
        }
      ]
    }
  },
  created () {
    this.warehouse()
  },
  methods: {
    async  warehouse () {
      const { data } = await warehouse({ ...this.frompage })
      this.tableData = data
      console.log(this.tableData)
    },
    addFn () {
      this.$router.push('/warehouse/detail/' + null)
      // this.warehouse()
    },
    // 修改
    update (row) {
      // 携带id跳转
      this.$router.push('/warehouse/detail/' + row.id)
      this.warehouse()
    },
    // 修改状态
    async  putwarehouse (row) {
      await this.$confirm(`确定要${row.status === 0 ? '启用' : '停用'}:, ${row.name
}吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
      await putwarehouse({
        id: row.id,
        status: row.status === 1 ? 0 : 1
      })
      this.warehouse()
    },
    // 删除
    async  del (id) {
      const res = await delwarehouse(id)
      this.$message.success('删除成功')
      console.log(res)
      this.warehouse()
    }, // 查询
    async  query () {
      const { data } = await warehouse(
        {
          like_code: this.form.num,
          like_name: this.form.name,
          status: this.form.state,
          current: 1,
          size: 10,
          descs: 'createTime'
        }
      )
      this.isshow = !data.records.length
      this.tableData = data

      this.$message.success('查询成功')
    },
    // 重置表单
    reset () {
      this.form = {
        num: '',
        name: '',
        state: ''
      }
    },
    pageChangeFn (page) {
      this.frompage.current = page
      this.warehouse()
    },
    pageSizeChangeFn (size) {
      this.frompage.size = size
      this.warehouse()
    }
  }
}
</script>

<style lang="less" scoped>
.emptyTip {
    border-top: 1px solid #f5efee;
    padding: 100px 0;
    margin: 0 auto;
    color: #b5abab;
    font-size: 14px;
    text-align: center;

}
.img {
  width: 160px;
  height: 160px;
  display: inline-block;
  background: url("http://www-wms-java.itheima.net/img/empty.4300e933.png")
    no-repeat;
  background-size: contain;
}
.app-main {
  min-height: calc(100vh - 50px);
  background-color: #fdfafa;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.divContent {
  margin-top: 15px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
}
.divContent .btnAdd {
  margin-left: 30px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.importantButton {
  background: #00be76;
  color: #fff;
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}
.divHead {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 6px 0 rgb(144 142 142 / 17%);
  padding: 30px;
}
/deep/.grid-content {
  margin-bottom: 10px;
  height: 18px;
  font-size: 12px;
  color: #887e7e;
  font-size: 12px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
}
/deep/.el-input--medium .el-input__inner {
  height: 40px;
  line-height: 40px;
  border: 1px solid #f8f5f5;
  background: #f8f5f5;
  border-radius: 6px;
}

/deep/.el-input__inner {
  padding-left: 12px;
  padding-right: 12px;
  box-sizing: border-box;
  color: #1f2d3d;
  display: inline-block;
  font-size: inherit;
  outline: none;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
}

.divButton {
  float: right;
}
.divButton .btnSearch {
  margin-right: 20px;
  margin-top: 25px;
}
.minorImportantButton {
  background: #ffb200;
  color: #332929;
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}
.unimportanceButton {
  background: #f8f5f5;
  color: #332929;
}
.unimportanceButton {
  height: 40px;
  border-radius: 20px;
  border: 0;
  font-size: 14px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: center;
  line-height: 40px;
  padding-left: 26px;
  padding-right: 26px;
  cursor: pointer;
  outline: 0;
}
span {
  cursor: pointer;
}
</style>
